﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Security.Cryptography;

namespace KeyGenerator
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TextBoxKey.Text = DateTime.Now.ToString("yyyyMM").GetHashCode().ToString().Substring(1, 5);
        }

        private void Button_Click_SHA1(object sender, RoutedEventArgs e)
        {
            string dateSeed = DateTime.Now.ToString("yyyyMM");

            //建立SHA1对象
            SHA1 sha = new SHA1Managed();

            //将mystr转换成byte[]
            byte[] dataToHash = UTF8Encoding.UTF8.GetBytes(dateSeed);

            //Hash运算
            byte[] dataHashed = sha.ComputeHash(dataToHash);

            //将运算结果转换成string
            string hash = BitConverter.ToString(dataHashed).Replace("-", "");

            TextBoxKey.Text = hash.Substring(1, 5);
        }
    }
}